<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增回收垃圾')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-trash-add">
			<div class="form-group">	
				<label class="col-sm-3 control-label">垃圾名称：</label>
				<div class="col-sm-8">
					<input id="name" name="name" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">垃圾类型名称：</label>

				<div class="col-sm-8">
					<select id="typeId" onchange="selecttype()" name="typeId" class="form-control m-b" th:with="list=${@trashType.selectTrashTypeList(null)}">
						<option th:each="trashtype : ${list}" th:text="${trashtype.name}" th:value="${trashtype.id}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">清单垃圾类型名称：</label>
				<div class="col-sm-8">
					<select id="trashDetailedId" name="trashDetailedId" class="form-control m-b" >
					</select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">单位类型：</label>
				<div class="col-sm-8">
					<div class="input-group" style="width: 100%">
						<select name="unitType" class="form-control m-b" th:with="type=${@dict.getType('sys_unit_type')}">
							<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
						</select>
					</div>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">状态：</label>
				<div class="col-sm-8">
					<div class="input-group" style="width: 100%">
						<select name="status" class="form-control m-b" th:with="type=${@dict.getType('sys_trash_status')}">
							<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
						</select>
					</div>
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "system/trash"
		$("#form-trash-add").validate({
			rules:{
				name:{
					required:true,
				},typeId:{
					required:true,
				},trashDetailedId:{
					required:true,
				},unitType:{
					required:true,
				},status:{
					required:true,
				}
			},
			focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/add", $('#form-trash-add').serialize());
	        }
	    }

		function selecttype() {
			debugger
			var  typeId =$("#typeId").val();
				$.ajax({
					url: "/system/trashDetailedList/listBytypeId?typeId="+typeId,
					type: "get",
					contentType: "application/json",
					timeout: 30000, //超时时间：30秒
					async: false,//false-同步（当这个ajax执行完后才会继续执行其他代码）；异步-与其他代码互不影响，一起运行。
					success: function (data) {
						$("#trashDetailedId").html("");
						if (data!=null&&data.length>0){
							for (var i = 0; i <data.length; i++) {
								var id=data[i].id;
								var typeDetailed=data[i].name;
								$("#trashDetailedId").append('<option value="'+id+'">'+typeDetailed+'</option>>')
							}
						}
					}, error: function (data) {
						console.log(data);
					}
				})
		};
		$(document).ready(function() {
			selecttype()
		})
	</script>
</body>
</html>
